package com.cheyunkeji.er.adapter.auction;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.utils.TimeUtils;
import com.cheyunkeji.er.bean.auction.ApplyRecordBean;
import com.cheyunkeji.er.view.auction.ApplyStatusTextView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/2/16 15:45.
 */

public class ApplyRecordAdapter extends MyBaseAdapter {

    public ApplyRecordAdapter(ArrayList<ApplyRecordBean> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_apply_record_lv_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ApplyRecordBean itemBean = (ApplyRecordBean) dataList.get(position);

        switch (itemBean.getState()) {
            case "1"://  已审核
                holder.tvCompanyName.setText(itemBean.getTitle());
                holder.tvApplyTime.setText(String.format("申请时间 ：%1$s",TimeUtils.millis2String(Long.valueOf(itemBean.getDateline()) * 1000)));
                holder.tvRefusedReason.setVisibility(View.GONE);
                holder.tvApplyResult.setApplySuccessed();
                break;
            case "2"://  申请中
                holder.tvCompanyName.setText(itemBean.getTitle());
                holder.tvApplyTime.setText(String.format("申请时间 ：%1$s",TimeUtils.millis2String(Long.valueOf(itemBean.getDateline()) * 1000)));
                holder.tvApplyResult.setApplyOnProcess();
                holder.tvRefusedReason.setVisibility(View.GONE);
                break;
            case "3"://  驳回请求
                holder.tvCompanyName.setText(itemBean.getTitle());
                holder.tvApplyTime.setText(String.format("申请时间 ：%1$s",TimeUtils.millis2String(Long.valueOf(itemBean.getDateline()) * 1000)));
                holder.tvRefusedReason.setVisibility(View.VISIBLE);
                holder.tvRefusedReason.setText(String.format("拒绝原因 ：%1$s",itemBean.getMessage()));
                holder.tvApplyResult.setApplyRefused();
                break;

            case "4"://  忽略请求
                holder.tvCompanyName.setText(itemBean.getTitle());
                holder.tvApplyTime.setText(String.format("申请时间 ：%1$s",TimeUtils.millis2String(Long.valueOf(itemBean.getDateline()) * 1000)));
                holder.tvApplyResult.setApplySuccessed();
                holder.tvRefusedReason.setVisibility(View.GONE);
                holder.tvApplyResult.setApplyIgnored();
                break;

            default:
                break;
        }
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.tv_apply_result)
        ApplyStatusTextView tvApplyResult;
        @BindView(R.id.tv_company_name)
        TextView tvCompanyName;
        @BindView(R.id.iv_is_new_msg)
        ImageView ivIsNewMsg;
        @BindView(R.id.tv_apply_time)
        TextView tvApplyTime;
        @BindView(R.id.tv_refused_reason)
        TextView tvRefusedReason;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
